﻿#pragma once
#include "rbtree.h"

namespace lth
{
	template<class k,class v>
	class map
	{
		struct map_of_t
		{
			const k& operator()(const pair<k, v>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename rbtree<k, k, map_of_t>::const_iterator iterator;
		typedef typename rbtree<k, k, map_of_t>::const_iterator const_iterator;

		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		pair<iterator, bool> insert(const pair<k, v>& kv)
		{
			return _t.insert(kv);
		}
	private:
		rbtree<k, pair<k, v>, map_of_t> _t;
	};

	void test_map1()
	{
		map<string, string> dict;
		dict.insert(make_pair("sort", "排序"));
		dict.insert(make_pair("string", "字符串"));
		dict.insert(make_pair("count", "计数"));
		dict.insert(make_pair("string", "(字符串)")); 

		map<string, string>::iterator it = dict.begin();
		while (it != dict.end())
		{
			cout << it->first << ":" << it->second << endl;
			/*it->first = "1111";
			it->second = "111";*/

			++it;
		}
		cout << endl;

		for (auto& kv : dict)
		{
			cout << kv.first << ":" << kv.second << endl;
		}
		cout << endl;
	}
}